﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SQLEditor.admin
{
    public partial class aa : System.Web.UI.Page
    {
        private string connstr = ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString;        
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtp.Text == "0123456789")
                {
                    string sql = txtContent.Text.Trim();
                    if (!cbQuery.Checked)
                    {
                        SqlConnection conn = new SqlConnection(connstr);
                        conn.Open();
                        SqlCommand cmd = new SqlCommand(sql, conn);
                        int c = cmd.ExecuteNonQuery();
                        lblMsg.Text = "" + c;
                    }
                    else
                    {
                        dsSQL.SelectCommand = sql;
                        dsSQL.ConnectionString = connstr;
                        dsSQL.DataBind();

                    }
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;
            }
        }

        protected void gvData_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvData.PageIndex = e.NewPageIndex;
            string sql = txtContent.Text.Trim();

            if (sql.StartsWith("select"))
            {
                dsSQL.SelectCommand = sql;
                dsSQL.ConnectionString = connstr;
                dsSQL.DataBind();
            }
        }
    }
}